import java.util.Arrays;

class Student{

    private String name="lisi";
    private int age;
    private String sex;

    public static String classRoom="java112";

    static {
        //静态代码块，只能初始化静态的成员变量
        classRoom="java";
        System.out.println("静态代码块");
    }




    {
        /*
        这个方法块定义在类内，方法外，叫做构造块或者实例代码或者非静态代码块
        作用就是初始化非静态成员
         */
        System.out.println("非静态代码块");
        this.name="zhangsan";
    }


    public Student(){
        //this("name",20,"female");
        System.out.println("不带参数的构造方法");
    }

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        System.out.println("带有三个参数的构造方法");
    }

    public Student(String name, int age, String sex, String classRoom) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.classRoom = classRoom;
    }





    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return this.name;
    }

    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }



    public void sleep() {
        System.out.println(this.getClassRoom());
        System.out.println(this.name+"正在睡觉");
    }

    public void show() {
        System.out.println("姓名:"+this.name+",性别:"+this.sex+",年龄:"+this.age);
    }



    public void eat() {
        System.out.println(this.name+"正在吃饭");
    }
    public static String getClassRoom() {
        return classRoom;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}












//类的使用者
public class Encapsulation {


    public static void main(String[] args) {
        Student student1 =new Student("张三",20,"男");
        System.out.println(student1);


        /*student1.show();*/



    }

    public static void main4(String[] args) {
        Student student =new Student();
        //System.out.println(student.getName());

        System.out.println("==================");

        Student student2=new Student();
    }


    public static void main3(String[] args) {

        int i=10;
        //if(i==10)//还有一个作用就是表明下面的代码有执行条件了
        {
            /*
            定义在方法里面的 叫局部/普通代码块,作用是标识作用域
            但是这种用法比较少见
             */
            int a=10;
            System.out.println(a);
        }
//        System.out.println(a);
    }










    public static void main2(String[] args) {
        /*


        Student student1=new Student("zhangsan",10,"male");
        Student student2=new Student("lisi",13,"male");
        Student student3=new Student("wangwu",15,"male");

        System.out.println(student1.classRoom);


        Student student1=null;
        System.out.println(Student.classRoom);

        System.out.println(student1.getName());
*/


        String ret=Student.getClassRoom();
        System.out.println(ret);

    }




















    public static void main1(String[] args) {
        Student s1=new Student();
//        s1.name="zhangsan";
        s1.setName("wangwu");
        System.out.println(s1.getName());
        s1.sleep();
    }
}
